package org.cwnuit.train.service;

import java.util.ArrayList;
import java.util.List;

import org.cwnuit.train.dao.StimeDAO;
import org.cwnuit.train.dao.WtypeDAO;
import org.cwnuit.train.domain.Stime;
import org.cwnuit.train.domain.Wtype;
import org.cwnuit.train.utils.PageModel;
@SuppressWarnings("all")
public class WtypeService {
	
	private WtypeDAO wtypeDAO = new WtypeDAO();
	private StimeDAO stimeDAO = new StimeDAO();
	

	public PageModel findByPage(int offset, int pagesize, String SQL) {
		PageModel pm = wtypeDAO.findByPage(offset, pagesize, SQL);
		List<Wtype> wtypes = pm.getDatas();
		List<Wtype> wtypelist = new ArrayList();
		for(Wtype wtype:wtypes){
			int wid = wtype.getWid();
			List<Stime> stimes = null;
			stimes = stimeDAO.findStimes("SELECT * FROM Stime WHERE wid = " + wid);
			wtype.setLcsnum(stimes.size());
			stimes = stimeDAO.findStimes("SELECT * FROM Stime WHERE sstate = 1 AND wid = " + wid);
			wtype.setWksnum(stimes.size());
			stimes = stimeDAO.findStimes("SELECT * FROM Stime WHERE sstate = 2 AND wid = " + wid);
			wtype.setJxznum(stimes.size());
			stimes = stimeDAO.findStimes("SELECT * FROM Stime WHERE sstate = 3 AND wid = " + wid);
			wtype.setYjsnum(stimes.size());
			wtypelist.add(wtype);
		}
		pm.setDatas(wtypelist);
		return pm;
	}
	public boolean addWtype(String SQL) {
		return wtypeDAO.addWtype(SQL);
	}

	public boolean updateWtype(String SQL) {
		return wtypeDAO.updateWtype(SQL);
	}
	
	public boolean deleteWtype(String SQL) {
		return wtypeDAO.deleteWtype(SQL);
	}
	
	public Wtype findWtype(String SQL) {
		return wtypeDAO.findWtype(SQL);
	}
	
	public List<Wtype> findWtypes(String SQL) {
		return wtypeDAO.findWtypes(SQL);
	}
}
